﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PROJECT_BOMBER.BLL
{
    // strategie de deplacement au clavier 2
    public class ControllerKeyboard2 : ControllerStrategy
    {

        #region Variable Etat Button + Fullscreen

        /*private static bool activeE = true;
        private static bool activeSpace = true;
        private static bool activeStart = true;
        private static bool fullscreen = false;*/

        #endregion

        public override void Control(ElementMove element1)
        {
            /*
            #region Key [Escape] => Exit
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Escape))
            {
                game.Exit();
            }
            #endregion

            #region Rotation : Unused, Key [Left][Right] => Zoom

            if (GamePad.GetState(player).ThumbSticks.Right.X > 0.7 || GamePad.GetState(player).ThumbSticks.Right.X < -0.7)
            {
                if (cam.Rotation + GamePad.GetState(player).ThumbSticks.Right.X / 200 >= -1 && cam.Zoom + GamePad.GetState(player).ThumbSticks.Right.X / 200 < 1)
                {
                    cam.Rotation += GamePad.GetState(player).ThumbSticks.Right.X / 200;
                }
            }

            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Left))
            {
                cam.Zoom -= 0.001f;
            }
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Right))
            {
                cam.Zoom += 0.001f;
            }
            #endregion

            #region Key [Up][Down][0] => Rotation character

            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Up))
            {
                element1.Rotation += 0.1f;
            }
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Down))
            {
                element1.Rotation -= 0.1f;
            }
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.NumPad0))
            {
                element1.Rotation = 0;
            }

            #endregion

            #region Key [Q][D][MAJ] => X : Speed X
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.NumPad3))
            {
                if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.LeftShift) && element1.Speed.X < element1.Speedmin.X * 3 && element1.ActiveSpeedX)
                {
                    element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X + (element1.Speedmin.X * 3) / 30, element1.Speed.Y);
                }
                else if (element1.Speed.X < element1.Speedmin.X / 2 && element1.ActiveSpeedX)
                {
                    element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X + (element1.Speedmin.X / 2) / 30, element1.Speed.Y);
                }
            }
            else if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.NumPad1))
            {
                if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.LeftShift) && element1.Speed.X > -element1.Speedmin.X * 3 && element1.ActiveSpeedX)
                {
                    element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X + (-element1.Speedmin.X * 3) / 30, element1.Speed.Y);
                }
                else if (element1.Speed.X > -element1.Speedmin.X / 2 && element1.ActiveSpeedX)
                {
                    element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X + (-element1.Speedmin.X / 2) / 30, element1.Speed.Y);
                }
            }
            else if (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.Q) && Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.D) && !element1.ActiveSpeedX)
            {
                element1.ActiveSpeedX = true;

                if (element1.Speed.X > 0)
                {
                    element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X - element1.Speedmax.X / 30, element1.Speed.Y);
                }
                else
                {
                    element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X + element1.Speedmax.X / 30, element1.Speed.Y);
                }
            }
            else
            {
                element1.Speed = new Microsoft.Xna.Framework.Vector2(0, element1.Speed.Y);
                element1.ActiveSpeedX = true;
            }
            #endregion

            #region Key [E] => active/desactive Fly
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.E) && activeE && element1.Speed.Y < 0)
            {
                element1.Fly = !element1.Fly;
                activeE = false;
            }
            else if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.E) && activeE)
            {
                element1.Fly = false;
            }

            if (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.E))
            {
                activeE = true;
            }
            #endregion

            #region Key [Space] => Jump & Double Jump & Jump right/left
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.NumPad2))
            {
                if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.NumPad2) && element1.Jump < 2 && activeSpace)
                {
                    if ((element1.Jump == 0 && element1.Onground > 0) || element1.Jump == 1)
                    {
                        element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X, -element1.Speedmax.Y / 7);

                        element1.Jump++;
                        activeSpace = false;
                    }
                }
            }

            if (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.NumPad2) && element1.Onground == 0)
            {
                activeSpace = true;
            }


            if (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.NumPad2) && element1.Onground > 0)
            {
                activeSpace = true;
                element1.Jump = 0;
            }

            if (element1.JumpWall && element1.Jump == 2 && element1.Onground == 0 && Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.NumPad2) && activeSpace && element1.Speed.Y < element1.Speedmax.Y / 10)
            {
                if (element1.Speed.X < 0)
                {
                    element1.JumpWall = false;
                    element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X + element1.Speedmax.X, -element1.Speedmax.Y / 7);
                    element1.ActiveSpeedX = false;
                    activeSpace = false;
                }
                else if (element1.Speed.X > 0)
                {
                    element1.JumpWall = false;
                    element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X - element1.Speedmax.X, -element1.Speedmax.Y / 7);
                    element1.ActiveSpeedX = false;
                    activeSpace = false;
                }
            }

            #endregion

            #region Key [A] => Attack
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.A) && element1.Speed.X != 0 && !element1.Fly)
            {
                element1.Attack = true;
            }
            else
            {
                element1.Attack = false;
            }
            #endregion

            #region {debug} Key [LeftAlt] => Allow Speed Y
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.LeftAlt))
            {
                if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Z))
                {
                    if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.LeftShift))
                    {
                        element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X, -element1.Speedmin.X * 5);

                    }
                    else
                    {
                        element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X, -element1.Speedmin.X * 2);
                    }
                }
                if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.S))
                {
                    if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.LeftShift))
                    {
                        element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X, element1.Speedmin.X * 5);

                    }
                    else
                    {
                        element1.Speed = new Microsoft.Xna.Framework.Vector2(element1.Speed.X, element1.Speedmin.X * 2);
                    }
                }
            }
            #endregion

            #region Key [F1] => Fullscreen
            if (!fullscreen && Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.F1) && activeStart)
            {
                graphics.PreferredBackBufferWidth = (int)screen.X;
                graphics.PreferredBackBufferHeight = (int)screen.Y;
                graphics.ToggleFullScreen();
                activeStart = false;
                fullscreen = !fullscreen;
            }
            else if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.F1) && activeStart)
            {
                graphics.PreferredBackBufferWidth = (int)screen.X - (160 * 3);
                graphics.PreferredBackBufferHeight = (int)screen.Y - (90 * 3);
                graphics.ToggleFullScreen();
                activeStart = false;
                fullscreen = !fullscreen;
            }
            if (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.F1))
            {
                activeStart = true;
            }
            #endregion
            */

        }

    }
}
